package com.jiazhong.backend.controller;

import com.jiazhong.backend.service.CategoryService;
import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.bean.Category;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService service;

    @RequestMapping("/list")
    public JsonResult findPage(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10") int size){
         return service.findPage(page,size);
    }

    @RequestMapping("/find")
    public JsonResult findSearch(@RequestParam(value = "name") String name,
            @RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10") int size){
        return service.findSearch(name, page, size);
    }

    @RequestMapping("/save")
    public JsonResult saveCategory(Category category){
        return service.saveCategory(category);
    }

    @RequestMapping("/remove")
    public JsonResult removeCategory(@RequestParam("id") String id){
        return service.removeCategory(id);
    }

    @RequestMapping("/exists")
    public  JsonResult findExists(@RequestParam("colum") String colum,@RequestParam("value") String value){
        return service.findExists(colum, value);
    }
}
